home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Magazin/MacEasy 2
/
Mac Magazin and MacEasy Magazine CD - Issue 02.iso
/
Sharewarebibliothek
/
Applikationen
/
Darkside
/
DarkSide of the Mac 4.1
/
FaderShell
/
Fader.c
next >
Wrap
Text File
|
1993-08-23
|
9KB
|
337 lines
/*
DarkSide 4.0 - a 7.0 dependant, system clean expandable screen saver.
copyright © 1990, 1991, 1992, 1993 by Tom Dowdy
All rights reserved.
This fader shell serves to dispatch requests from the main DarkSide code
into the appropriate entry points.
*/
#include <StdArg.h>
#include <Memory.h>
#include <Packages.h>
#include <Errors.h>
#include "Fader.h"
/* ------------------------------------------------------------------------ */
/* GLOBAL HANDLING ROUTINES */
/* ------------------------------------------------------------------------ */
OSErr CreateA5World(Ptr * a5World);
void DisposeA5World(Ptr a5World, Ptr appA5);
void DebugLongInt(long aLong);
/* ------------------------------------------------------------------------ */
OSErr FaderEntry(long selector, Ptr *a5World, MachineInfoPtr machineInfo, ...)
{
OSErr anErr;
va_list nextArg;
// start stripping optional arguments
va_start(nextArg, machineInfo);
switch(selector)
{
case preflightFader:
{
long *minTicks, *maxTicks;
minTicks = va_arg(nextArg, long*);
maxTicks = va_arg(nextArg, long*);
anErr = CreateA5World(a5World);
if (anErr == noErr)
{
(void) SetA5((long) *a5World);
BlockMove(machineInfo->applicationQD, &qd, sizeof(qd));
anErr = PreflightFader(machineInfo, minTicks, maxTicks);
BlockMove(&qd, machineInfo->applicationQD, sizeof(qd));
}
}
break;
case initializeFader:
(void) SetA5((long) *a5World);
BlockMove(machineInfo->applicationQD, &qd, sizeof(qd));
anErr = InitializeFader(machineInfo);
BlockMove(&qd, machineInfo->applicationQD, sizeof(qd));
break;
case idleFader:
(void) SetA5((long) *a5World);
anErr = IdleFader(machineInfo);
break;
case disposeFader:
{
(void) SetA5((long) *a5World);
BlockMove(machineInfo->applicationQD, &qd, sizeof(qd));
anErr = DisposeFader(machineInfo);
BlockMove(&qd, machineInfo->applicationQD, sizeof(qd));
DisposeA5World(*a5World, (Ptr)machineInfo->applicationA5);
}
break;
case updateFader:
(void) SetA5((long) *a5World);
anErr = UpdateFader(machineInfo);
break;
case hitFader:
{
DialogPtr dPtr;
long itemHit;
long itemOffset;
dPtr = va_arg(nextArg, DialogPtr);
itemHit = va_arg(nextArg, long);
itemOffset = va_arg(nextArg, long);
anErr = HitFader(machineInfo, dPtr, itemHit, itemOffset);
}
break;
default:
// function not found error
anErr = fnfErr;
break;
}
va_end(nextArg);
(void) SetA5(machineInfo->applicationA5);
return(anErr);
} // FaderEntry
/* ------------------------------------------------------------------------ */
/* DEBUGGING ROUTINES */
/* ------------------------------------------------------------------------ */
void DebugLongInt(long theLong)
{
Str255 theString;
NumToString(theLong, theString);
DebugStr(theString);
} // DebugLongInt
/* ------------------------------------------------------------------------ */
/* FUN A5 STUFF - See Tech note 256 for details */
/* ------------------------------------------------------------------------ */
long A5Size();
void A5Init(Ptr theA5);
OSErr CreateA5World(Ptr * a5World)
{
OSErr anErr;
Ptr theWorld = nil;
Handle worldHandle;
worldHandle = BestNewHandle(A5Size());
anErr = MemError();
if (anErr == noErr)
{
MoveHHi(worldHandle);
HLock(worldHandle);
theWorld = *worldHandle;
theWorld += + A5Size() - 32;
A5Init(theWorld);
// very important if anyone wants to call SwapMMUMode
theWorld = StripAddress(theWorld);
}
*a5World = theWorld;
return(anErr);
} // CreateA5World
/* ------------------------------------------------------------------------ */
void DisposeA5World(Ptr a5World, Ptr appA5)
{
Handle worldHandle;
(void) SetA5((long) appA5);
worldHandle = RecoverHandle(a5World - A5Size() + 32);
DisposHandle(worldHandle);
} // DisposeA5World
/* ------------------------------------------------------------------------ */
/* FADER UTILS */
/* ------------------------------------------------------------------------ */
Handle BestNewHandle(Size theSize)
/*
Tries to get the handle from the temp memory first, if that fails, it goes
to the application.
*/
{
Handle theHandle;
OSErr anErr;
theHandle = TempNewHandle(theSize, &anErr);
if (theHandle == nil)
theHandle = NewHandle(theSize);
return(theHandle);
} // BestNewHandle
/* ------------------------------------------------------------------------ */
RgnHandle BestNewRgn()
/*
Tries to get a rgn handle from the temp memory first, if that fails, it goes
to the application. Needs enough room in the app heap to create the region
in the first place.
*/
{
RgnHandle theRgn;
OSErr anErr;
// make a region
theRgn = NewRgn();
if (theRgn != nil)
{
RgnHandle theHandle;
short regionSize;
// try to make something the same size in the temp memory
regionSize = GetHandleSize((Handle) theRgn);
theHandle = (RgnHandle) TempNewHandle(regionSize, &anErr);
if (anErr == noErr)
{
// if we get it, use that one for our region
BlockMove(*theRgn, *theHandle, regionSize);
DisposeRgn(theRgn);
theRgn = theHandle;
}
}
return(theRgn);
} // BestNewRgn
/* ------------------------------------------------------------------------ */
short Rnd(long max)
/*
Returns a number > 0 and < max
*/
{
unsigned long value;
value = (unsigned short)max * (unsigned short)Random();
value >>= 16;
return(value);
} // Rnd
/* ------------------------------------------------------------------------ */
void PlaceRectOnScreen(
MachineInfoPtr machineInfo, // give info about the machine here
short width, // width of rect, can be 0
short height, // height of rect, can be 0
Rect * placedRect, // Placed rect is returned here
Rect * margins, // margins around screen, can be nil
short * whichScreen) // screen index returned here, can be nil
{
Rect screenRect;
short pickScreen;
// pick a random screen
pickScreen = Rnd(machineInfo->numScreens);
screenRect = machineInfo->theScreens[pickScreen].bounds;
if (whichScreen != nil)
*whichScreen = pickScreen;
if (margins != nil)
{
screenRect.top += margins->top;
screenRect.left += margins->left;
screenRect.bottom -= margins->bottom;
screenRect.right -= margins->right;
}
screenRect.right -= width;
screenRect.bottom -= height;
if (placedRect != nil)
{
placedRect->top = screenRect.top + Rnd(screenRect.bottom - screenRect.top);
placedRect->left = screenRect.left + Rnd(screenRect.right - screenRect.left);
placedRect->bottom = placedRect->top + height;
placedRect->right = placedRect->left + width;
}
} // PlaceRectOnScreen
/* ------------------------------------------------------------------------ */
/* CALLBACK DEFINES
/* ------------------------------------------------------------------------ */
#pragma parameter __D0 DoWritePreferencesHandle(__A0)
OSErr DoWritePreferencesHandle(Ptr M, Handle h, ResType theType) =
{ 0x7000, 0x487B, 0x000A, 0x2F3C, 0x0800, 0x0004, 0x4ED0};
#pragma parameter __D0 DoReadPreferencesHandle(__A0)
OSErr DoReadPreferencesHandle(Ptr M, Handle *h, ResType theType) =
{ 0x7000, 0x487B, 0x000A, 0x2F3C, 0x0800, 0x0008, 0x4ED0};
#pragma parameter __D0 DoPlayResourceSnd(__A0)
OSErr DoPlayResourceSnd(Ptr M, short theID, Boolean async) =
{ 0x7000, 0x487B, 0x000A, 0x2F3C, 0x0800, 0x000C, 0x4ED0};
/* ------------------------------------------------------------------------ */
/* CALLBACK WRAPERS
/* ------------------------------------------------------------------------ */
OSErr WritePreferencesHandle(MachineInfoPtr machineInfo, Handle h, ResType theType)
{
OSErr anErr;
long curA5;
curA5 = SetA5(machineInfo->applicationA5);
anErr = DoWritePreferencesHandle(machineInfo->callbackLoader, h, theType);
SetA5(curA5);
return(anErr);
} // WritePreferencesHandle
/* ------------------------------------------------------------------------ */
OSErr ReadPreferencesHandle(MachineInfoPtr machineInfo, Handle *h, ResType theType)
{
OSErr anErr;
long curA5;
curA5 = SetA5(machineInfo->applicationA5);
anErr = DoReadPreferencesHandle(machineInfo->callbackLoader, h, theType);
SetA5(curA5);
return(anErr);
} // ReadPreferencesHandle
/* ------------------------------------------------------------------------ */
OSErr PlayResourceSnd(MachineInfoPtr machineInfo, short theID, Boolean async)
{
OSErr anErr;
long curA5;
curA5 = SetA5(machineInfo->applicationA5);
anErr = DoPlayResourceSnd(machineInfo->callbackLoader, theID, async);
SetA5(curA5);
return(anErr);
} // PlayResourceSnd